package cyf.ParkPlace.controller;

import cyf.Owner.bean.OwnerVo;
import cyf.Owner.service.OwnerService;
import cyf.ParkPlace.service.ParkPlaceService;
import cyf.Tools.StringHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * 车位管理controller层
 */
@Controller
@RequestMapping("/ParkManage")

public class ParkPlaceController {

    @Autowired
    private ParkPlaceService parkPlaceService;

    /**
     * 跳转车位管理页面
     * @return
     */
    @RequestMapping("parkplace")
    public String ShowOwner(){
        return "ParkPlace";
    }

    /**
     * 跳转车位新增页面
     */
    @RequestMapping("insertPark")
    public String InsertPark(){
        return "NewParkPlace";
    }

    /**
     * 分页查询所有车位
     * @param park_area
     * @param park_number
     * @param car_plate
     * @param sffp
     * @param pageCurrent
     * @return
     * @throws Exception
     */
    @RequestMapping("getParkPlaceMessage")
    @ResponseBody
    public Map<String,Object> GetOwners(String park_area, String park_number,String car_plate,int sffp, Integer pageCurrent) throws Exception {
        Map<String,Object > param = new HashMap<>();
        param.put("park_area",park_area);
        param.put("park_number",park_number);
        param.put("car_plate",car_plate);
        param.put("sffp",sffp);
        Map<String,Object> map = parkPlaceService.getAllParkPlace(param,pageCurrent);
        return map ;
    }

    /**
     * 删除一个车位的信息
     * @param car_parkplace_id
     * @return
     */
    @RequestMapping("deleteParkPlace")
    @ResponseBody
    public Map<String,Object> deleteCarPlace(int car_parkplace_id){
        return this.parkPlaceService.deleteParkPlace(car_parkplace_id);
    }

    /**
     * 车位分配方法
     * @param car_plate
     * @param car_parkplace_id
     * @return
     */
    @RequestMapping("FPParkPlace")
    @ResponseBody
    public Map<String,Object> FPParkPlace(String car_plate,int car_parkplace_id){
        if(StringHelper.isEmpty(car_plate)){
            Map<String,Object> result = new HashMap<>();
            result.put("empty",1);
            return result;
        }
        return this.parkPlaceService.FPParkPlace(car_plate,car_parkplace_id);
    }

    /**
     * 获取所有车位区域
     * @return
     */
    @RequestMapping("QueryAllParkArea")
    @ResponseBody
    public Map<String,Object> QueryAllParkArea(){
        return this.parkPlaceService.QueryParkArea();
    }

    /**
     * 新增一个车位
     * @param park_area
     * @param park_number
     * @return
     */
    @RequestMapping("insertParkPlace")
    @ResponseBody
    public Map<String,Object> insertParkPlace(String park_area,String park_number){
       return this.parkPlaceService.insertParkPlace(park_area,park_number);
    }
}
